
import _ from "lodash";
import { Component, Vue, Prop } from "vue-property-decorator";
//import { ipcRenderer } from "electron";
import { PrinterInfo, WebviewTag } from 'electron';
import { PRINTER_LIST, PRINTER_OPEN, PRINTER_CLOSE, PRINTER_DO } from './../bglib/printer_helper';
import RootNode from "@/components/ObjectCom/RootNode.vue";

const CONN_KEY = "lowdb-test-01";
const FILE_KEY = "lowdb_t.json";

@Component({
    components: {
        RootNode
    }
})
export default class PrinterTest extends Vue {
    public labelCol = { span: 4 }
    public wrapperCol = { span: 14 }

    public printer_list: string[] = []
    public printer_selected = 0
    public get printer_name() { return this.printer_list.length > 0 ? this.printer_list[this.printer_selected] : ""; }

    async created() {
        let res = await this.$ipcR.send(PRINTER_LIST);
        let { printerList } = res;
        this.printer_list = _.map(printerList, "name");
    }

    async print_view() {
        let res = await this.$ipcR.send(PRINTER_OPEN, { page: "first_test", width: 250 });
    }

    async print_close() {
        let res = await this.$ipcR.send(PRINTER_CLOSE);
    }

    async print_do() {
        console.log("start print.");
        let res = await this.$ipcR.send(PRINTER_DO, { deviceName: this.printer_name });
        console.log(res);
    }

}